<?php
  session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Senty FB :)</title>
<link rel="shortcut icon" href="http://www.sentyfb.altervista.org/img/title.ico" type="image"/>
<link rel="icon" href="http://www.sentyfb.altervista.org/img/title.ico" />
</head>

<body>
<center>
<h1>Welcome To Senty Facebook!!</h1>
</center>
<h4> 

<?php
  require_once('../../src/facebook.php');

  $fbconfig['appid' ] = "294539840579833";
  $fbconfig['secret'] = "fa6384c4966c76b0a3de06bf0af4b2a0";
  $fbconfig['baseurl'] = "http://sentyfb.altervista.org";

  // Facebook obj initialization
  $facebook = new Facebook(array(
	'appId' => $fbconfig['appid'],
	'secret' => $fbconfig['secret'],
	'cookie' => false,
  ));
  
  // Fb obj params  
  $params = array(
//  scope => 'ads_management, create_event, create_note, email, export_stream, friends_about_me, friends_activities, friends_birthday, friends_checkins, friends_education_history, friends_events, friends_games_activity, friends_groups, friends_hometown, friends_interests, friends_likes, friends_location, friends_notes, friends_online_presence, friends_photo_video_tags, friends_photos, friends_relationship_details, friends_relationships, friends_religion_politics, friends_status, friends_subscriptions, friends_videos, friends_website, friends_work_history, manage_friendlists, manage_notifications, manage_pages, offline_access, photo_upload, publish_checkins, publish_stream, read_friendlists, read_insights, read_mailbox, read_requests, read_stream, rsvp_event, share_item, sms, status_update, user_about_me, user_activities, user_birthday, user_checkins, user_education_history, user_events, user_games_activity, user_groups, user_hometown, user_interests, user_likes, user_location, user_notes, user_online_presence, user_photo_video_tags, user_photos, user_relationship_details, user_relationships, user_religion_politics, user_status, user_subscriptions, user_videos, user_website, user_work_history, video_upload, xmpp_login',
  scope => 'email, user_status, friends_status, status_update, user_about_me, user_birthday, friends_about_me, friends_activities, manage_pages, xmpp_login, read_friendlists, read_stream, user_likes, publish_stream',
  redirect_uri => 'http://sentyfb.altervista.org/Leonardo/Crawler/index.php'
  );
  
  $user = $facebook->getUser();

  $facebook_s = serialize($facebook);
  
  if (!isset($_SESSION['facebook_s']));
	$_SESSION['facebook_s'] = $facebook_s;

  // Login or logout url will be needed depending on current user state.
  if ($user) {
	  $logoutUrl = $facebook->getLogoutUrl();
	  echo " &nbsp &nbsp <a href=$logoutUrl>Logout :( </a><br>";
  }
  else {
	  $loginUrl = $facebook->getLoginUrl($params);
	  echo "<br><a href=$loginUrl> Login :) </a>";	
  }

?>
</h4>
<?
  
  // We may or may not have this data based on whether the user is logged in.
  // If we have a $user id here, it means we know the user is logged into
  // Facebook, but we don't know if the access token is valid. An access
  // token is invalid if the user logged out of Facebook.
  if ($user) {
	try {
	  // Proceed knowing you have a logged in user who's authenticated.
	  $user_profile = $facebook->api('/me');

	  echo "<br> Hi <strong>".$user_profile['first_name']."!</strong>. Welcome and enjoy this sentiment analysis service! Your facebook ID is ".$user.".<br><br>";
	  
	?>
	Get your
	<a href="./list.php"> friend list</a>
    
	<?
	
//	$result = $facebook->api( 
//	array('method' => 'fql.query', 'query' => 'SELECT uid, name FROM user, profile WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me() ) ORDER BY name') );
//	echo '<pre>'.print_r($result, true).'</pre>';
	
	
	  
	} catch (FacebookApiException $e) {
		error_log($e);
		echo "<br /><br />ECCEZIONE INTERCETTATA. CONTROLLARE LOG SERVER.<br />";
		echo "Reloading Page. Please wait just a few seconds";
		?>
        <br />
        <META HTTP-EQUIV="refresh" CONTENT="3"> 
        <?
	}			  
  }
?> 

<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<h3>Senty Facebook 0.0.1 alfa</h3>
<br />
<br />
<table border="1">
<tr>
<td><center><b><font size="+1">Log of changes</font></b></center></td>
</tr>
<font color="#003300">
<tr><td>1) Started the creation of the project design <br /></td></tr>
<tr><td>2) Started the development of the crawler <br /></td></tr>
<tr><td>3) Created a simple user home page <br /></td></tr>
</font>
</table>

<?php phpinfo(INFO_MODULES); ?>

</body>
</html>



